package com.hottv.meeting.videomeeting.module.white.data;

import com.google.gson.JsonArray;
import com.google.gson.JsonIOException;
import com.google.gson.JsonObject;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by chengwenqiang on 2019/6/3.
 */

public class DocumentInfo {
    public String convertStatus ="";
    public String reasean ="";
    public int totalPageSize = 0;
    public int convertedPageSize= 0;
    public int convertedPercentage = 0;

    public List<ItemInfo> itemList = new ArrayList<>();


    public static DocumentInfo  fromJson(JsonObject json)
    {
        DocumentInfo info = new DocumentInfo();
        try{
            info.convertStatus = json.get("convertStatus").getAsString();
            info.reasean = json.get("reason").getAsString();
            info.totalPageSize = json.get("totalPageSize").getAsInt();
            info.convertedPageSize = json.get("convertedPageSize").getAsInt();
            info.convertedPercentage = json.get("convertedPercentage").getAsInt();

            JsonArray jsonList = json.getAsJsonArray("staticConversionFileList");
            for (int i=0;i<jsonList.size();i++)
            {
                JsonObject itemJson = jsonList.get(i).getAsJsonObject();
                ItemInfo itemInfo = ItemInfo.fromJson(itemJson);
                info.itemList.add(itemInfo);
            }

        }catch (JsonIOException e)
        {
            e.printStackTrace();
        }
        return info;
    }

}
